package com.iflytek.application.common.springjdbc;

import java.util.ArrayList;
import java.util.List;

/***
 * Created by guanxf on 2015/12/16.
 */
public class Pagination {
	/*** 是否是第一页 */
	private	boolean first=false;
	/*** 是否是最后一页 */
	private 	boolean last=false;
	/*** 当前页的记录条数 */
	private 	int numberOfElements;
	/** 当前页 */
	private  String  sort;

	/** 当前页 */
	private int number = 1;
	/** 每页显示数 */
	private int size =20;
	/** 总行数 */
	private int totalElements = 0;
	/** 总页数 */
	private int totalPages;
	/** 当前页在数据库中的起始行 */
	private int startElement =0;
	/**  要显示的数据集 */
    private List<?> content=new ArrayList();

	public Pagination() {
	}

	public Pagination(int currentPage, int pageSize, int totalRow) {
		this.number = currentPage;
		this.size = pageSize;
		this.totalElements = totalRow;
	}

	public Pagination(int pageSize) {
		this.size = pageSize;
		this.number = 1;
		this.totalElements = 1;
	}

	public int getNumber() {
		return number;
	}

	public void setNumber(int number) {
		if (number ==0) {
			return;
		}
		this.number = number;
	}

	public int getSize() {
		return size;
	}

	public void setSize(int size) {
		this.size = size;
	}

	public int getTotalElements() {
		return totalElements;
	}

	public void setTotalElements(int totalElements) {
		this.totalElements = totalElements;
	}

	public int getStartElement() {
		if (this.number > 1) {
			this.startElement = (this.number - 1) * this.size;
		} else {
			this.startElement = 0;
		}
		return startElement;
	}

	public void setStartElement(int startElement) {
		this.startElement = startElement;
	}

	public List<?> getContent() {
		return content;
	}

	public void setContent(List<?> content) {
		this.content = content;
	}

	public int getTotalPages() {
		this.totalPages = this.totalElements / this.size;
		if (this.totalElements % this.size != 0) {
			this.totalPages += 1;
		}
		return totalPages;
	}

	public void setTotalPages(int totalPages) {
		this.totalPages = totalPages;
	}

	public String getSort() {
		return sort;
	}

	public void setSort(String sort) {
		this.sort = sort;
	}

	public boolean isFirst() {
		if(this.getNumber()==1 ){
			first=true;
		}
		return first;
	}

	public void setFirst(boolean first) {
		this.first = first;
	}

	public boolean isLast() {
		if(this.getNumber()==this.getTotalPages()){
           last=true;
		}
		return last;
	}

	public void setLast(boolean last) {
		this.last = last;
	}

	public int getNumberOfElements() {
		numberOfElements=this.getContent().size();
		return numberOfElements;
	}

	public void setNumberOfElements(int numberOfElements) {
		this.numberOfElements = numberOfElements;
	}


	/** 页码 */
//	private List<Integer> pages = new ArrayList<Integer>();
	/** 查询参数保存 javabean的形式 */
//	private Object queryObject ;

/*	public List<Integer> getPage() {
		this.pages.clear();
		for (int i = 0; i < this.totalPages; i++) {
			try {
				this.pages.add((i + 1));
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return pages;
	}*/


/*	public void setPage(List<Integer> pages) {
		this.pages = pages;
	}

	public Object getQueryObject() {
		return queryObject;
	}

	public void setQueryObject(Object queryObject) {
		this.queryObject = queryObject;
	}
*/
}
